package bean;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

/**
 * Created by shiyanqi on 19/4/9.
 */
public class BaseBean {
    private String code;

    private String msg;

    private String data;

    public String getCode() {
        if (this.code == "") {
            return "";
        } else {
            return code;
        }
    }

    public String getMsg() {
        if (this.msg == "") {
            return "";
        } else {
            return msg;
        }
    }

    public String getData() {
        return data;
    }

    public boolean isOk() {
        if (this.code != "" && code.equals("0")) {
            return true;
        } else {
            return false;
        }
    }

    public void parse(String in) {
        try{
            JSONObject root = JSON.parseObject(in);
            String code = root.getString("code");
            String msg = root.getString("msg");
            this.code = code;
            this.msg = msg;
            if (root.containsKey("data")) {
                this.data = root.getString("data");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
